using UnityEngine;
using System.Collections;

public class SpawnAmmo : MonoBehaviour {
	
	public Transform Ammo;
	public float timer;
	public float spawnTimer;
	public static int AmmoInScene;
	
	// Use this for initialization
	void Start () 
	{		
		spawnTimer = Random.Range(20,60);
	}
	
	// Update is called once per frame
	void Update () 
	{
		if(Connection.playersConnected)
		{
			timer += Time.deltaTime;
			
			if(timer >= spawnTimer)
			{
				for(int j = 0; j < 3; j++)
				{
					if(AmmoInScene < 3)
					{
						Instantiate(Ammo, new Vector3(Random.Range(-25,25), 0.2f, Random.Range(-20,20)), Quaternion.identity);
						AmmoInScene++;
					}
				}
				
				spawnTimer = Random.Range(20,60);
				timer = 0;
			}
		}
	}
}
